package cn.devpt.demo.controller;

import cn.devpt.demo.entity.PtDemoTable;
import cn.devpt.demo.service.PtDemoTableService;
import cn.devpt.dev.base.bean.PtMsg;
import cn.devpt.dev.base.bean.PtQuery;
import cn.devpt.dev.base.bean.PtGrid;
import cn.devpt.dev.util.PtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author admin
 * @date 2019-05-23
 */
@Controller
@RequestMapping("/login/demo/PtDemoTable")  //注意路径
public class PtDemoTableController {

    @Autowired
    private PtDemoTableService ptDemoTableService;


    /**
     * 通用列表查询
     *
     * @param params
     * @return
     */
    @RequestMapping(value = "/find")
    @ResponseBody
    public PtGrid find(@RequestBody PtQuery ptQuery) {
        return ptDemoTableService.find(ptQuery);
    }

    /**
     * 查询
     *
     * @param params 参数
     * @return 查询结果
     */
    @RequestMapping(value = "/findOne")
    @ResponseBody
    public PtDemoTable findone(String tableId) {
        if (PtUtil.strIsNull(tableId)) {// 增加时默认初值
            PtDemoTable entity = new PtDemoTable();
            entity.setName("后端初值");
            entity.setDateTime(PtUtil.getDateTime());
            return entity;
        }
        return ptDemoTableService.findOne(tableId);
    }

    /**
     * 单条删除
     */
    @RequestMapping(value = "/remove")
    @ResponseBody
    public PtMsg remove(@RequestBody PtDemoTable ptdemotable) {
        ptDemoTableService.remove(ptdemotable);
        return PtUtil.genMsg();
    }


    /**
     * 批量删除
     */
    @RequestMapping(value = "/removeAll")
    @ResponseBody
    public PtMsg removeAll(@RequestBody List<PtDemoTable> ptdemotableLs) {
        ptDemoTableService.removeAll(ptdemotableLs);
        return PtUtil.genMsg();
    }

    /**
     * 保存资源信息
     *
     * @param PtDemoTable
     * @return
     */
    @RequestMapping("/save")
    @ResponseBody
    public PtMsg save(@RequestBody PtDemoTable ptdemotable) {
        return ptDemoTableService.save(ptdemotable);
    }

    /**
     * 保存资源信息
     *
     * @param PtDemoTable
     * @return
     */
    @RequestMapping("/saveAll")
    @ResponseBody
    public PtMsg saveAll(@RequestBody List<PtDemoTable> ptdemotableLs) {
        return ptDemoTableService.saveAll(ptdemotableLs);
    }

    @RequestMapping("/addManyData")
    @ResponseBody
    public PtMsg addManyData(int startNum) {
        ptDemoTableService.addManyData(startNum);
        return PtUtil.genMsg();
    }
}

